import React from "react"

import { httpB } from "../helper/request"
import { IHandListItemResponse, IHandListParams, IHandListSummary } from "./type"

const useApi = () => {
	const { useState } = React
	const [loading, setLoading] = useState(false)
	async function generalHttpB<T>(url: string, body: object | undefined, config: object = {}) {
		setLoading(true)
		let ret = await httpB.post<T>(url, body, config)
		setLoading(false)
		return ret
	}

	async function generalGetB<T>(url: string, body: object | undefined) {
		setLoading(true)
		const ret = await httpB.get<T>(url, body)
		setLoading(false)
		return ret
	}

	const getDxhandLlistBend = (body?: IHandListParams) => {
		const ret = generalHttpB<Business.TableResourceType<IHandListItemResponse, IHandListSummary[]>>(
			"/dx-game-data-manager/dxhand/list",
			body
		)

		return ret
	}
	const getDxhandListExportBend = (body: IHandListParams) => {
		const ret = generalHttpB("/dx-game-data-manager/dxhand/listExport", body, {
			responseType: "blob",
			timeout: 1000 * 60
		})

		return ret
	}

	const getHandPageListBend = (body: any) => {
		const ret = generalHttpB<Business.TableResourceType<any>>("/dx-game-data-manager/dxhand/handPageList", body)

		return ret
	}

	const showGameReviewCardListBend = (body: any) => {
		const ret = generalHttpB("/dx-game-data-manager/game/showGameReviewCardList", body)

		return ret
	}

	const getGameReviewDeatailListBend = (body: any) => {
		const ret = generalHttpB("/dx-game-data-manager/game/getGameReviewDeatailList", body)

		return ret
	}

	const getDxhandDetailBend = (body: any) => {
		const ret = generalGetB("/dx-game-data-manager/dxhand/detail", body)

		return ret
	}

	return {
		loading,
		getDxhandLlistBend,
		getDxhandListExportBend,
		getHandPageListBend,
		showGameReviewCardListBend,
		getGameReviewDeatailListBend,
		getDxhandDetailBend
	}
}

export default useApi
